//
//  GarbageClassHeaderView.swift
//  Community
//
//  Created by MAC on 2019/8/2.
//  Copyright © 2019 ZKJ. All rights reserved.
//

import UIKit

class SWPTGarbageClassHeaderView: UIView {

    var selected:((Int)->Void)?
 
    override init(frame: CGRect) {
        super.init(frame: frame)
        let leftMargin: CGFloat = 25
        let width: CGFloat = (kScreenW - leftMargin * 2 - 20) / 2
        let height: CGFloat = width * 130 / 94
        
        let images = ["gan","shi","huishou","youhai"]
        for (idx,imageName) in images.enumerated() {
            let btn = ClassBtn(type: .custom)
            btn.setImage(UIImage(named: imageName), for: .normal)
            
            let x: CGFloat = leftMargin + CGFloat((idx)%2) * (width + 20)
            let y: CGFloat = 10 + CGFloat((idx) / 2) * ( height + 20)
            
//            btn.layer.shadowColor = UIColor.lightGray.cgColor
//            btn.layer.shadowOffset = CGSize(width: 1, height: 1)
//            btn.layer.shadowOpacity = 2
//            btn.layer.shadowRadius = 7;
           
            btn.backgroundColor = UIColor.white
            btn.frame = CGRect(x: x, y: y, width: width, height: height)
            btn.layer.cornerRadius = 15
            btn.layer.borderWidth = 1
            btn.layer.borderColor = UIColor.lightGray.withAlphaComponent(0.3).cgColor
            btn.tag = idx
            btn.addTarget(self, action: #selector(clicked(_:)), for: .touchUpInside)
            self.addSubview(btn)
        }
    }
    @objc func clicked(_ sender: UIButton) {
        self.selected?(sender.tag)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}


class ClassBtn: UIButton {
    override var isHighlighted: Bool {
        get {
            return false
        }
        set {
            
        }
    }
}
